// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var base = require(CONFIG.BasePath + "js/enterprise/base");
	var router = require("../hash/pageRouter");
	var css_pickup = require("./accountPickupDelayApplication.css");
	var databind = require("databind");
	var constant = require("constant");
	var financeId;
	var tools = require("tools");

	var init = function(page) {
		financeId = page.params.financeId || base.getUrlParam("financeId");
		inquirePickupApplicationPageList();
		router.init();
		initEvent();
	};

	var initEvent = function() {
		if (base.getData("sid") == null) {
			location.href = "../login/login.html";
		}

		//点击项目基本详情financeDetail
		$(".financeDetail").unbind("click").click(function(){
			router.route("account/accountDetail.html?financeId="+financeId,true);
                	
		});

		if($("#accountPickupDelayApplication tr").length==1){
			$("#accountPickupDelayApplication .pickupDelayContent").html('<div class="emptyData">亲，您没有待还款的提货申请，所以没办法申请延期还款！</div>');
		}
		
		$("#accountPickupDelayApplication").on("change", ".delayRemark", function(){
			$(".delayRemark").val($(this).val());
		});
		
		$("#accountPickupDelayApplication").on("change", ".delayReson", function(){
			$(".delayReson").val($(this).val());
		});

		$("#pickupDelaySubmitBtn").unbind("click").click(function() {
			for (var j = 0; j < $(".pickupdelayCheck:checked").length; j++) {
				databind.submitDom($($(".pickupdelayCheck:checked")[j]).parents("tr"), function() {
					if(j == $(".pickupdelayCheck:checked").length){
						router.route("account/accountDetail.html?financeId=" + financeId);
					}
				});
			}
		});
	};

	//查询提货申请列表
	var inquirePickupApplicationPageList = function() {
		base.fnAjax({
			action: "inquireNormalPickupApplicationPageList.json",
			async: false,
			oData: {
				pageSize: 100,
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#pickupDelayListTpl").html();
					var html = juicer(tpl, data);
					$("#pickupDelayListBody").html(html);
					tools.inquireCommonSelectorList(9, $(".delayReson"));
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};

	return {
		init: init
	};
});